<?php

namespace App\Api\Controllers;

use App\Api\Dao\TransferMoneyDao;
use App\Api\Dao\UserDao;
use App\Api\Logic\TransferMoneyLogic;
use App\Api\Logic\UserLogic;
use App\Exceptions\ValidationException;
use Illuminate\Http\Request;

/**
 * 用户转账
 */
class TransferMoneyController extends BaseController
{
    /**
     * 向好友发起转账
     * @return \Illuminate\Http\JsonResponse
     */
    public function to_user_money(Request $request,TransferMoneyLogic $transferMoneyLogic,TransferMoneyDao $transferMoneyDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->post());
        $transferMoneyLogic->to_user_money($data);
        $result = $transferMoneyDao->to_user_money($data);
        return $this->success($result);
    }

    /**
     * 获取转账的详情
     * @return \Illuminate\Http\JsonResponse
     */
    public function getToUserMoneyInfo(Request $request,TransferMoneyLogic $transferMoneyLogic,TransferMoneyDao $transferMoneyDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $transferMoneyLogic->getToUserMoneyInfo($data);
        $result = $transferMoneyDao->getToUserMoneyInfo($data);
        return $this->success($result);
    }

    /**
     * 转账成功后的二次确认
     * @return \Illuminate\Http\JsonResponse
     */
    public function confirmUserMoney(Request $request,TransferMoneyLogic $transferMoneyLogic,TransferMoneyDao $transferMoneyDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $transferMoneyLogic->confirmUserMoney($data);
        $result = $transferMoneyDao->confirmUserMoney($data);
        return $this->success($result);
    }

    /**
     * 根据手机号获取用户信息
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getMobileInfo(Request $request,UserLogic $userLogic,UserDao $userDao)
    {
        $data = array_merge($request->all());
        $userLogic->getMobileInfo($data);
        $result = $userDao->getMobileInfo($data);
        return $this->success($result);
    }
}
